package
{
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;
	import flash.utils.Timer;
	
	public class PointBurst extends Sprite
	{
		private static const FONT_FACE:String = "Arial";
		private static const FONT_SIZE:int = 20;
		private static const FONT_BOLD:Boolean = true;
		private static const FONT_COLOR:Number = 0xFF0000;
		
		private static const ANIM_STEP:int = 50;
		private static const ANIM_STEP_TIME:int = 25;
		
		private static const START_SCALE:Number = 0.3;
		private static const END_SCALE:Number = 2.5;
		
		private var tField:TextField;
		private var burstSprite:Sprite;
		private var parentMc:MovieClip;
		private var animTimer:Timer;
		public function PointBurst(mc:MovieClip,pts:Object,x:Number,y:Number)
		{
			
			var tFormat:TextFormat = new TextFormat();
			tFormat.font = FONT_FACE;
			tFormat.size = FONT_SIZE;
			tFormat.bold = FONT_BOLD;
			tFormat.color = FONT_COLOR;
			tFormat.align = "center";
			
			tField = new TextField();
			tField.embedFonts = true;
			tField.selectable = false;
			tField.autoSize = TextFieldAutoSize.CENTER;
			tField.defaultTextFormat = tFormat;
			tField.text = pts.toString();
			//trace(tField.text);
			tField.x = -tField.width / 2;
			tField.y = -tField.height / 2;
			
			burstSprite = new Sprite();
			burstSprite.x = x;
			burstSprite.y = y;
			burstSprite.scaleX = START_SCALE;
			burstSprite.scaleY = START_SCALE;
			burstSprite.alpha = 0;
			burstSprite.addChild(tField);
			parentMc = mc;
			parentMc.addChild(burstSprite);
			parentMc.setChildIndex(burstSprite,parentMc.numChildren-1);
			animTimer = new Timer(ANIM_STEP_TIME, ANIM_STEP);
			animTimer.addEventListener(TimerEvent.TIMER, rescaleBurst);
			animTimer.addEventListener(TimerEvent.TIMER_COMPLETE, removeBurst);	
			animTimer.start();
		}
		public function rescaleBurst(evt:TimerEvent)
		{
			var percentDone:Number = evt.currentTarget.currentCount / ANIM_STEP;
			burstSprite.scaleX = (1.0 - percentDone) * START_SCALE + percentDone * END_SCALE;
			burstSprite.scaleY = (1.0 - percentDone) * START_SCALE + percentDone * END_SCALE;
			burstSprite.alpha = 1.0 - percentDone;
			burstSprite.y -= 2;
		}
		public function removeBurst(evt:TimerEvent)
		{
			burstSprite.removeChild(tField);
			parentMc.removeChild(burstSprite);
			tField = null;
			burstSprite = null;
			delete this;
		}
	}
}